package com.atguigu.gmall.item.controller;

import org.redisson.api.RCountDownLatch;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author:lyd
 * @Date:2023/8/21 20:53
 * @Version:1.0
 * @Description 测试分布式锁redisson
 **/
@RestController
public class RedissonController {

    @Autowired
    private RedissonClient redissonClient;

    @GetMapping("/call/dragon")
    public String callDragon() {
        RCountDownLatch qinglong = redissonClient.getCountDownLatch("qinglong");
        qinglong.trySetCount(7);
        try {
            qinglong.await();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "神龙出世，嗷嗷嗷。。。。";
    }

    @GetMapping("/collect/ball")
    public String collectBall() {
        RCountDownLatch qinglong = redissonClient.getCountDownLatch("qinglong");
        qinglong.countDown();
        return "收集到一颗龙珠";
    }
}
